/**      
*  @Title:  PubAppController.java  
*  @Package  com.zjdiepu.www.rest.api.pub  
*    
*  @author  zhangpp
*  @date  2017年9月19日  下午2:00:22  
*  @version  V1.0      
*/
package com.zjdiepu.www.rest.api.pub.action;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import net.sf.json.JSONObject;

import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.google.gson.Gson;
import com.zjdiepu.www.base.BaseController;
import com.zjdiepu.www.base.annotation.Add;
import com.zjdiepu.www.base.core.ApiResponse;
import com.zjdiepu.www.base.core.BaseException;
import com.zjdiepu.www.base.enums.type.AttachmentSort;
import com.zjdiepu.www.base.enums.type.AttachmentType;
import com.zjdiepu.www.base.enums.type.CreditPeopleType;
import com.zjdiepu.www.base.enums.type.DataDicType;
import com.zjdiepu.www.base.enums.type.ModeIDType;
import com.zjdiepu.www.base.enums.type.ResultFlagType;
import com.zjdiepu.www.common.consts.SystemConsts;
import com.zjdiepu.www.common.util.CollectionInitUtil;
import com.zjdiepu.www.commpent.handler.TokenUserHelper;
import com.zjdiepu.www.dao.base.OtherAttachmentsMapper;
import com.zjdiepu.www.dao.yw.YwTransferMapper;
import com.zjdiepu.www.dao.zpp.PublicDao;
import com.zjdiepu.www.ibiz.base.IDpBaseDataDictionaryService;
import com.zjdiepu.www.ibiz.cache.ICachedDictionaryService;
import com.zjdiepu.www.ibiz.fk.IFkAuditListService;
import com.zjdiepu.www.ibiz.other.IOtherAuditInfoService;
import com.zjdiepu.www.ibiz.system.IBaseCustomerService;
import com.zjdiepu.www.ibiz.system.IBaseRemitAccountService;
import com.zjdiepu.www.ibiz.system.IBaseSalersmanService;
import com.zjdiepu.www.ibiz.system.IBaseSysParamsService;
import com.zjdiepu.www.ibiz.yw.IYwBusinessCarService;
import com.zjdiepu.www.ibiz.yw.IYwBusinessExtrasService;
import com.zjdiepu.www.ibiz.yw.IYwBusinessLoanService;
import com.zjdiepu.www.ibiz.yw.IYwBusinessService;
import com.zjdiepu.www.ibiz.yw.IYwFeesService;
import com.zjdiepu.www.ibiz.zpp.PublicService;
import com.zjdiepu.www.ibiz.zpp.YwShenQingZxService;
import com.zjdiepu.www.ibiz.zpp.YwShouLiService;
import com.zjdiepu.www.ibiz.zx.IZxCreditQueryService;
import com.zjdiepu.www.ibiz.zx.IZxQueryCreditApplyService;
import com.zjdiepu.www.ibiz.zx.IZxQueryCreditApplySubService;
import com.zjdiepu.www.model.base.dto.DpBaseDataDictionary;
import com.zjdiepu.www.model.base.dto.OtherAttachments;
import com.zjdiepu.www.model.base.dto.SysUser;
import com.zjdiepu.www.model.base.ext.DpBaseDataDictionaryExt;
import com.zjdiepu.www.model.system.dto.BaseRemitAccount;
import com.zjdiepu.www.model.yw.dto.YwBusiness;
import com.zjdiepu.www.model.yw.dto.YwBusinessCar;
import com.zjdiepu.www.model.yw.dto.YwBusinessExtras;
import com.zjdiepu.www.model.yw.dto.YwBusinessLoan;
import com.zjdiepu.www.model.yw.dto.YwFees;
import com.zjdiepu.www.model.yw.dto.YwTransfer;
import com.zjdiepu.www.model.zx.request.DiepuCreditApplyModifyExt;
import com.zjdiepu.www.model.zx.request.ZxRestRequest;
import com.zjdiepu.www.rest.api.pub.ext.AnJieDayBiaoAppExt;
import com.zjdiepu.www.rest.api.pub.ext.DiepuAnJieDayBiaoAppExt;
import com.zjdiepu.www.rest.api.pub.ext.DiepuAnJieDayBiaoAppList;
import com.zjdiepu.www.rest.api.pub.ext.DiepuCreditApplyListExt;
import com.zjdiepu.www.rest.api.pub.ext.DiepuCreditApplyListGo;
import com.zjdiepu.www.rest.api.pub.ext.GetBankRate;
import com.zjdiepu.www.rest.api.pub.ext.GetDiepuCarTransferExt;
import com.zjdiepu.www.rest.api.pub.vo.DicTypeNameYwFeesVo;
import com.zjdiepu.www.util.CommonUtil;
import com.zjdiepu.www.util.ExceptionHelper;
import com.zjdiepu.www.util.HtmlUtil;

/**            
 *  项目名称：diepu-parent-rest      
 *  类名称：PubAppController      
 *  类描述：      
 *  创建人：zhangpp
 *  创建时间：2017年9月19日  下午2:00:22      
 *  修改人：zhangpp
 *  修改时间：2017年9月19日  下午2:00:22      
 *  修改备注：      
 *  @version  V1.0          
 */
@RestController
@RequestMapping(value= "PubAppController", produces="application/json;charset=UTF-8")
@Api(tags = {"移动端API，作者：张虹剑   电话：15158822934，心情：在远方，曾年少痴狂，怀着梦跨越苍茫"}, produces="application/json;charset=UTF-8")
public class PubAppController extends BaseController {
	private final Logger logger = LoggerFactory.getLogger(getClass());
	
	@Resource
    private TokenUserHelper tokenUserHelper;
	
	@Resource
	private PublicService publicService;
	
	@Resource
	private PublicDao publicDao;
	
	@Resource
	private ICachedDictionaryService cachedDictionaryService; 
	
	@Resource
	private IBaseRemitAccountService iBaseRemitAccountService;
	
	@Resource
	private IYwBusinessService ywBusinessService;
	
	@Resource
	private IDpBaseDataDictionaryService iDpBaseDataDictionaryService;
	
	@Resource
	private YwShouLiService YwShouLiService;
	
	@Resource
	private IYwFeesService ywFeesService;
	
	@Resource
	private IFkAuditListService fkAuditListService;
	
	@Resource
	private IOtherAuditInfoService otherAuditInfoService; 
	
	@Resource
	private IZxCreditQueryService zxCreditQueryService;
	
	@Resource
	private IZxQueryCreditApplyService zxQueryCreditApplyService;
	
	@Resource
	private IZxQueryCreditApplySubService zxQueryCreditApplySubService;
	
	@Resource
	private IYwBusinessExtrasService ywBusinessExtrasService;
	
	@Resource
	private IBaseSalersmanService baseSalersmanService;
	
	@Resource
	private IBaseCustomerService baseCustomerService;
	
	@Resource
	private IBaseSysParamsService baseSysParamsService;
	
	@Resource
	private IYwBusinessLoanService ywBusinessLoanService;
	
	@Resource
	private YwTransferMapper ywTransferMapper;
	
	@Resource
	private IYwBusinessCarService iYwBusinessCarService;
	
	@Resource
	private YwShenQingZxService ywShenQingZxService;
	
	@Resource
	private OtherAttachmentsMapper otherAttachmentsMapper;
	
	
	@ApiOperation(value = "征信修改", response = Boolean.class, httpMethod="POST")
    @ApiImplicitParams({
    	@ApiImplicitParam(name = SystemConsts.MOBILE_FLAG, defaultValue="ios", value = "machineType", required = true, paramType = "header", dataType = "String"),
    	@ApiImplicitParam(name = SystemConsts.HEADER_FOR_TOKEN, defaultValue="token", value = "token", required = true, paramType = "header", dataType = "String")
    })
	@RequestMapping(value="diepuCreditApplyModify",method = RequestMethod.POST, produces="application/json;charset=UTF-8")
    public ApiResponse diepuCreditApplyModify(@Validated(Add.class) @RequestBody DiepuCreditApplyModifyExt diepuCreditApplyModifyExt) throws Exception
	{
    	SysUser currentUser = tokenUserHelper.getUser();
    	ywShenQingZxService.diepuCreditApplyModify(diepuCreditApplyModifyExt, currentUser);
    	
    	//开始生成征信文档
    	ywShenQingZxService.diepuCreatedWord(currentUser,diepuCreditApplyModifyExt);
        return ApiResponse.success(true);
    }
	
	@ApiOperation(value = "征信修改列表操作", response = Boolean.class, httpMethod="POST")
    @ApiImplicitParams({
    	@ApiImplicitParam(name = SystemConsts.MOBILE_FLAG, defaultValue="ios", value = "machineType", required = true, paramType = "header", dataType = "String"),
    	@ApiImplicitParam(name = SystemConsts.HEADER_FOR_TOKEN, defaultValue="token", value = "token", required = true, paramType = "header", dataType = "String")
    })
	@RequestMapping(value="diepuCreditApplyListGo",method = RequestMethod.POST, produces="application/json;charset=UTF-8")
    public Map<String, Object> diepuCreditApplyListGo(@Validated(Add.class) @RequestBody DiepuCreditApplyListGo diepuCreditApplyListGo) throws Exception {
		tokenUserHelper.getUser();
		
		Map<String, Object> maps = success();
		maps.put("overdue", false);
		StringBuilder sqlXmls = new StringBuilder();
		sqlXmls.append("SELECT")
		.append(" sub.id replaceId, ")
		.append(" sub.query_credit_apply_id queryCreditApplyId, ")
		.append(" apply.dealer_id dealerId, ")
		.append(" d.dealer_name dealerName, ")
		.append(" sub.cus_name cusName, ")
		.append(" sub.cus_no cusNo, ")
		.append(" sub.tel1, ")
		.append(" sub.bank_code, ")
		.append(" sub.credit_people_type creditPeopleType ")
		.append("FROM")
		.append(" zx_query_credit_apply_sub sub ")
		.append(" left join zx_query_credit_apply apply ")
		.append(" on apply.id = sub.query_credit_apply_id ")
		.append(" left join dp_base_dealer_info d ")
		.append(" on d.id = apply.dealer_id ")
		.append(" where sub.dp_status = 1 ")
		.append(" and sub.id = '"+diepuCreditApplyListGo.getReplaceId()+"' ");
		Map<String, String> result = publicDao.selectMapsSql(sqlXmls.toString());
		maps.put("result", result);
		
		if(MapUtils.isNotEmpty(result)) {
			String bankName = cachedDictionaryService.getName(result.get("bank_code"), DataDicType.LOAN_BANK);
			result.put("bankName", bankName);
			
			String creditPeopleType = result.get("creditPeopleType");
			String queryCreditApplyId = result.get("queryCreditApplyId");
			String queryCreditApplySubId = result.get("replaceId");
			
			result.put("attachmentType", AttachmentType.IMAGE.getCode());
			result.put("modeId", ModeIDType.ZXCX.getCode());
			
			if(CreditPeopleType.ZHU_JIE_REN.getCode().equals(creditPeopleType)) { //主借人
				result.put("attachmentSort", AttachmentSort.SHEN_FEN_ZHENG_MING.getCode());
			} else if(CreditPeopleType.PEI_OU.getCode().equals(creditPeopleType)) { //配偶
				result.put("attachmentSort", AttachmentSort.PEI_OU_SHEN_FEN_ZHENG_MING.getCode());
			} else if(CreditPeopleType.DAN_BAO_REN.getCode().equals(creditPeopleType)) { //担保人
				OtherAttachments otherAttachments = new OtherAttachments();
				otherAttachments.setAttachmentType(AttachmentType.IMAGE.getCode());
				otherAttachments.setModeId(ModeIDType.ZXCX.getCode());
//				otherAttachments.setDpStatus(DpStatus.NORMAL.getCode()); 所有的，历史痕迹也必须作为参考
				otherAttachments.setDataid(queryCreditApplyId);
				otherAttachments.setSubDataid(queryCreditApplySubId);
				otherAttachments = otherAttachmentsMapper.selectRefined(otherAttachments);
				if(null == otherAttachments) {
					logger.error("征信申请附件丢失。申请ID：{}，子申请ID：{}。", queryCreditApplyId, queryCreditApplySubId);
					ExceptionHelper.thow(ResultFlagType.MISSING.getCode().toString(), "征信申请附件丢失");
				}
				result.put("attachmentSort", otherAttachments.getAttachmentSort());
			}
		}
        return maps;
    }
	
	
	
	@ApiOperation(value = "征信修改列表", response = Boolean.class, httpMethod="POST")
    @ApiImplicitParams({
    	@ApiImplicitParam(name = SystemConsts.MOBILE_FLAG, defaultValue="ios", value = "machineType", required = true, paramType = "header", dataType = "String"),
    	@ApiImplicitParam(name = SystemConsts.HEADER_FOR_TOKEN, defaultValue="token", value = "token", required = true, paramType = "header", dataType = "String")
    })
	@RequestMapping(value="diepuCreditApplyList",method = RequestMethod.POST, produces="application/json;charset=UTF-8")
    public ApiResponse diepuCreditApplyList(@Validated(Add.class) @RequestBody DiepuCreditApplyListExt diepuCreditApplyListExt) throws Exception {
		tokenUserHelper.getUser();
		String salersmanId = diepuCreditApplyListExt.getSalersmanId();
		
		StringBuffer sqlXmls = new StringBuffer();
	    sqlXmls.append("SELECT")
	    .append(" t.id replaceId,")
	    .append(" if(t.credit_people_type = '03','主借人',if(t.credit_people_type = '01','配偶','担保人')) creditPeopleType,")
	    .append(" t.cus_name customerName,")
	    .append(" t.cus_no customerNo,")
	    .append(" t.type_data typeData,")
	    .append(" t.reason_back,")
	    .append(" t.bank_code")
	    .append(" FROM ")
	    .append(" zx_query_credit_apply_sub t")
	    .append(" join zx_credit_query qu")
	    .append(" on qu.query_credit_apply_sub_id = t.id")
	    .append(" where t.dp_status = 1")
	    .append(" and qu.credit_query_status = 20")
	    .append(" and qu.salersman_id_then = '"+ salersmanId+"' limit 10 ");
	    List<Map<String, String>> reuslt = publicDao.queryWhereSql(sqlXmls.toString());
	    if(null != reuslt && reuslt.size() > 0) {
	    	for(int i=0;i<reuslt.size();i++) {
	    		Map<String, String> m = reuslt.get(i);
	    		String bankName = cachedDictionaryService.getName(m.get("bank_code"), DataDicType.LOAN_BANK);
	    		m.put("bankName", bankName);
	    		
	    		String creditResultMark = cachedDictionaryService.getName(m.get("reason_back"), DataDicType.CREDIT_RETURNED_REASON);
	    		creditResultMark = HtmlUtil.filterHtml(creditResultMark);
	    		if(StringUtils.isBlank(creditResultMark)) {
	    			m.put("creditResultMark", "无");
	    		}
	    		else {
	    			m.put("creditResultMark", HtmlUtil.filterHtml(creditResultMark));
	    		}
	    	}
	    }
        return ApiResponse.success(reuslt);
    }
	
	
	//手机端征信提交
	@ApiOperation(value = "征信提交", response = Boolean.class, httpMethod="POST")
    @ApiImplicitParams({
    	@ApiImplicitParam(name = SystemConsts.MOBILE_FLAG, defaultValue="ios", value = "machineType", required = true, paramType = "header", dataType = "String"),
    	@ApiImplicitParam(name = SystemConsts.HEADER_FOR_TOKEN, defaultValue="token", value = "token", required = true, paramType = "header", dataType = "String")
    })
	@RequestMapping(value="diepuCreditApply",method = RequestMethod.POST, produces="application/json;charset=UTF-8")
    public ApiResponse diepuCreditApply(@Validated(Add.class) @RequestBody ZxRestRequest zxRestRequest) throws Exception {
    	SysUser currentUser = tokenUserHelper.getUser();
    	ywShenQingZxService.diepuCreditApply(zxRestRequest, currentUser);
    	//开始生成征信文档
    	ywShenQingZxService.diepuCreatedWord(currentUser,zxRestRequest);
        return ApiResponse.success(true);
    }
	
	
	//贷中业务>二手车过户
	@ApiOperation(value = "贷中业务>二手车过户 ",response = Integer.class, httpMethod="POST")
    @ApiImplicitParams({
    	@ApiImplicitParam(name = SystemConsts.MOBILE_FLAG, defaultValue="ios", value = "machineType", required = true, paramType = "header", dataType = "String"),
    	@ApiImplicitParam(name = SystemConsts.HEADER_FOR_TOKEN, defaultValue="token", value = "token", required = true, paramType = "header", dataType = "String")
    })
	@RequestMapping(value="getDiepuCarTransfer",method = RequestMethod.POST, produces="application/json;charset=UTF-8")
	public ApiResponse getDiepuCarTransfer(@RequestBody GetDiepuCarTransferExt getDiepuCarTransferExt)
	{
		tokenUserHelper.getUser();
		Map<String, Object> maps = success();
		if(null == getDiepuCarTransferExt) {
			throw new BaseException(ResultFlagType.PARAM_EMPTY.getCode().toString(),ResultFlagType.PARAM_EMPTY.getValue());
		}
		
		String busiId = getDiepuCarTransferExt.getBusiId();
		
		if(StringUtils.isBlank(busiId)) {
			throw new BaseException(ResultFlagType.PARAM_EMPTY.getCode().toString(),ResultFlagType.PARAM_EMPTY.getValue());
		}
		
		//过户信息
    	YwTransfer ywTransfer = new YwTransfer();
    	ywTransfer.setBusiId(busiId);
    	ywTransfer.setDpStatus(1);
    	ywTransfer = ywTransferMapper.selectRefined(ywTransfer);
    	if(null != ywTransfer) {
    		ywTransfer.setColorCarDisplay(cachedDictionaryService.getName(ywTransfer.getColorCar(), DataDicType.CAR_COLOR));
    		if(StringUtils.isNotBlank(ywTransfer.getRemarks()))
    		{
    			ywTransfer.setRemarks(HtmlUtil.filterHtml(ywTransfer.getRemarks()));
    		}
    		if(null == ywTransfer.getPrice())
    		{
    			ywTransfer.setPrice(0.0);
    		}
    		maps.put("ywBusinessCar", ywTransfer);
    	} else {
    		YwBusinessCar ywBusinessCar = new YwBusinessCar();
        	ywBusinessCar.setBusiId(busiId);
        	ywBusinessCar.setDpStatus(1);
        	ywBusinessCar = iYwBusinessCarService.selectRefined(ywBusinessCar);
        	if(null != ywBusinessCar)
        	{
        		if(StringUtils.isNotBlank(ywBusinessCar.getRemarks()))
        		{
        			ywBusinessCar.setRemarks(HtmlUtil.filterHtml(ywBusinessCar.getRemarks()));
        		}
        		ywBusinessCar.setColorCarDisplay(cachedDictionaryService.getName(ywBusinessCar.getColorCar(), DataDicType.CAR_COLOR));
        	}
        	if(null == ywBusinessCar.getPrice())
    		{
        		ywBusinessCar.setPrice(0.0);
    		}
        	maps.put("ywBusinessCar", ywBusinessCar);
    	}
    	return ApiResponse.success(maps);
	}
	
	//贷中业务>二手车过户
	@ApiOperation(value = "贷中业务>二手车过户 ",response = Integer.class, httpMethod="POST")
    @ApiImplicitParams({
    	@ApiImplicitParam(name = SystemConsts.MOBILE_FLAG, defaultValue="ios", value = "machineType", required = true, paramType = "header", dataType = "String"),
    	@ApiImplicitParam(name = SystemConsts.HEADER_FOR_TOKEN, defaultValue="token", value = "token", required = true, paramType = "header", dataType = "String")
    })
	@RequestMapping(value="diepuCarTransfer",method = RequestMethod.POST, produces="application/json;charset=UTF-8")
	public Map<String, Object> diepuCarTransfer(@RequestBody YwTransfer ywTransfer)
	{
		SysUser currentUser = tokenUserHelper.getUser();
		if(null == currentUser)
		{
			throw new BaseException(ResultFlagType.LOGIN_TIMEOUT.getCode().toString(),ResultFlagType.LOGIN_TIMEOUT.getValue());
		}
		Map<String, Object> maps = success();
		YwShouLiService.diepuCarTransfer(currentUser,ywTransfer,null,"3");
		return maps;
	}
	
	
	//获取银行利率
	@ApiOperation(value = "获取银行利率，作者：张虹剑 ",response = Integer.class, httpMethod="POST")
    @ApiImplicitParams({
    	@ApiImplicitParam(name = SystemConsts.MOBILE_FLAG, defaultValue="ios", value = "machineType", required = true, paramType = "header", dataType = "String"),
    	@ApiImplicitParam(name = SystemConsts.HEADER_FOR_TOKEN, defaultValue="token", value = "token", required = true, paramType = "header", dataType = "String")
    })
	@RequestMapping(value="getBankRate",method = RequestMethod.POST, produces="application/json;charset=UTF-8")
	public Map<String, Object> getBankRate(@RequestBody String requestJsonString)
	{
		SysUser currentUser = tokenUserHelper.getUser();
		if(null == currentUser)
		{
			throw new BaseException(ResultFlagType.LOGIN_TIMEOUT.getCode().toString(),ResultFlagType.LOGIN_TIMEOUT.getValue());
		}
		Map<String, Object> maps = success();
		if(StringUtils.isBlank(requestJsonString))
		{
			throw new BaseException(ResultFlagType.PARAM_EMPTY.getCode().toString(),ResultFlagType.PARAM_EMPTY.getValue());
		}
		GetBankRate getBankRate = new Gson().fromJson(requestJsonString, GetBankRate.class);
		if(null == getBankRate)
		{
			throw new BaseException(ResultFlagType.PARAM_EMPTY.getCode().toString(),ResultFlagType.PARAM_EMPTY.getValue());
		}
		
		String bankCode = getBankRate.getBankCode();
		String monthNum = getBankRate.getMonthNum();
		
		if(StringUtils.isBlank(bankCode) || StringUtils.isBlank(monthNum))
		{
			throw new BaseException(ResultFlagType.PARAM_EMPTY.getCode().toString(),ResultFlagType.PARAM_EMPTY.getValue());
		}
		
		String sqlXmls = "select t.id,t.bank_rate from other_bank_rate t where t.dp_status = 1 and t.bank_code = '"+bankCode+"' and t.month_num = '"+monthNum+"' order by t.sort_value asc";
		List<Map<String, Double>> result = publicService.selectDoubleSql(sqlXmls);
		maps.put("result", result);
		return maps;
	}
	
	
	//查询按揭日报表数据信息 
	@ApiOperation(value = "查询按揭日报表数据信息，作者：张虹剑 ",response = Integer.class, httpMethod="POST")
    @ApiImplicitParams({
    	@ApiImplicitParam(name = SystemConsts.MOBILE_FLAG, defaultValue="ios", value = "machineType", required = true, paramType = "header", dataType = "String"),
    	@ApiImplicitParam(name = SystemConsts.HEADER_FOR_TOKEN, defaultValue="token", value = "token", required = true, paramType = "header", dataType = "String")
    })
	@RequestMapping(value="getAnJieDayBiaoApp",method = RequestMethod.POST, produces="application/json;charset=UTF-8")
	public Map<String, Object> getAnJieDayBiaoApp(@RequestBody String requestJsonString)
	{
		Map<String, Object> maps = success();
		maps.put("overdue", false);
		
		SysUser currentUser = tokenUserHelper.getUser();
		if(null == currentUser)
		{
			throw new BaseException(ResultFlagType.LOGIN_TIMEOUT.getCode().toString(),ResultFlagType.LOGIN_TIMEOUT.getValue());
		}
		
		AnJieDayBiaoAppExt anJieDayBiaoAppExt = new Gson().fromJson(requestJsonString, AnJieDayBiaoAppExt.class);
		
		if(null == anJieDayBiaoAppExt)
		{
			throw new BaseException(ResultFlagType.PARAM_EMPTY.getCode().toString(),ResultFlagType.PARAM_EMPTY.getValue());
		}
		
		String busiId = anJieDayBiaoAppExt.getBusiId();
		String unitCode = anJieDayBiaoAppExt.getUnitCode();
		
		if(StringUtils.isBlank(busiId) || StringUtils.isBlank(unitCode))
		{
			throw new BaseException(ResultFlagType.PARAM_EMPTY.getCode().toString(),"busiId or unitCode is null");
		}
		
		
		//查询业务信息表数据
		YwBusiness business = ywBusinessService.selectById(busiId);
		maps.put("business", business);
		
		//按揭服务费
		double anjieAmount = 0;
		if(null != business)
		{
			if(null != business.getSignLoanAmount() && null != business.getRealLoanAmount())
			{
				anjieAmount = business.getSignLoanAmount() - business.getRealLoanAmount();
			}
		}
		maps.put("anjieAmount", anjieAmount);
		
		//费用信息
		DpBaseDataDictionaryExt dpBaseDataDictionaryExt = new DpBaseDataDictionaryExt();
		dpBaseDataDictionaryExt.setBaseWhere();
	    dpBaseDataDictionaryExt.withOutPage();
	    dpBaseDataDictionaryExt.setParentValue(DataDicType.FUND_ITEM.getCode());
	    dpBaseDataDictionaryExt.setAddedValue1("01"); //启用的明细
	    dpBaseDataDictionaryExt.setOrderSql("`VALUE`");
		List<DpBaseDataDictionary> dictionary = iDpBaseDataDictionaryService.selectByExt(dpBaseDataDictionaryExt);
		maps.put("dictionary", dictionary);
		
		//显示的费用信息
		String sqlXmls = " select t.id,t.item_code,t.amount_item from yw_fees_sub t where t.busi_id = '"+busiId+"' and t.dp_status = 1 order by t.item_code asc ";
		List<Map<String, String>> ywFeesSub = publicService.queryWhereSql(sqlXmls);
		maps.put("ywFeesSub", ywFeesSub);
		
		int sumAmount = 0;
		for(int i=0;i<ywFeesSub.size();i++)
		{
			Map<String, String> fMap = ywFeesSub.get(i);
			JSONObject json = CommonUtil.getJSONObject(fMap);
			sumAmount += json.getInt("amount_item");
		}
		maps.put("sumAmount", sumAmount);
		
		//投保收益信息
		YwFees ywFees = new YwFees();
		ywFees.setBusiId(busiId);
		ywFees.setDpStatus(1);
		ywFees = ywFeesService.selectRefined(ywFees);
		maps.put("ywFees", ywFees);
		
		//返回的数据字典
		DicTypeNameYwFeesVo dicTypeNameYwFeesVo = new DicTypeNameYwFeesVo();
		if(null != ywFees)
		{
			dicTypeNameYwFeesVo.setTypeBalance(ywFees.getTypeBalance());
			dicTypeNameYwFeesVo.setTypeBalanceName(cachedDictionaryService.getName(ywFees.getTypeBalance(), DataDicType.SETTLEMENT_TYPE));
			dicTypeNameYwFeesVo.setRebateType(ywFees.getRebateType());
			dicTypeNameYwFeesVo.setRebateTypeName(cachedDictionaryService.getName(ywFees.getRebateType(), DataDicType.REBATE_TYPE));
		}
		maps.put("dicTypeNameYwFeesVo", dicTypeNameYwFeesVo);
		
		
		//取征信押金
		YwBusinessExtras ywBusinessExtras = new YwBusinessExtras();
		ywBusinessExtras.setBusiId(busiId);
		ywBusinessExtras.setCodeExtras("AddGeposit");
		ywBusinessExtras.setDpStatus(1); 
		ywBusinessExtras = ywBusinessExtrasService.selectRefined(ywBusinessExtras);
		if(null == ywBusinessExtras)
		{
			maps.put("valueExtras", "0");
		}
		else
		{
			maps.put("valueExtras", ywBusinessExtras.getValueExtras());
		}
		
		//按揭服务费
		YwBusinessLoan ywBusinessLoan = new YwBusinessLoan();
		ywBusinessLoan.setBusiId(busiId);
		ywBusinessLoan.setDpStatus(1);
		ywBusinessLoan = ywBusinessLoanService.selectRefined(ywBusinessLoan);
		maps.put("ywBusinessLoan", ywBusinessLoan);
		if(null == ywBusinessLoan)
		{
			ywBusinessLoan = new YwBusinessLoan();
			ywBusinessLoan.setServicePrice(0.0);
		}
		if(null != ywBusinessLoan)
		{
			if(null == ywBusinessLoan.getServicePrice())
			{
				ywBusinessLoan.setServicePrice(0.0);
			}
		}
		
		
		//打款名单维护查询   unitCode 来自  base_salersman
		if(StringUtils.isBlank(unitCode))
		{
			throw new BaseException(ResultFlagType.FAIL.getCode().toString(),"unitCode is null");
		}
		
		BaseRemitAccount baseRemitAccount = new BaseRemitAccount();
		baseRemitAccount.setOrgCode(unitCode);
		baseRemitAccount.setFundChannel("zy");
		baseRemitAccount.setDpStatus(1);
		BaseRemitAccount remit = iBaseRemitAccountService.selectRefined(baseRemitAccount);
		if(null != remit && !("").equals(remit))
		{
			remit.setBankId(cachedDictionaryService.getName(remit.getBankId(), DataDicType.BANK));
			maps.put("remit", remit);
			return maps;
		}
		
		for(int i=0;i<5;i++)
		{
			if(unitCode.length() > 4)
			{
				unitCode = unitCode.substring(0, unitCode.length()-3);
				baseRemitAccount.setOrgCode(unitCode);
				baseRemitAccount.setFundChannel("zy");
				remit = iBaseRemitAccountService.selectRefined(baseRemitAccount);
				if(null != remit && !("").equals(remit))
				{
					remit.setBankId(cachedDictionaryService.getName(remit.getBankId(), DataDicType.BANK));
					maps.put("remit", remit);
					return maps;
				}
			}
			
			if(unitCode.length() == 4)
			{
				baseRemitAccount.setOrgCode(unitCode);
				baseRemitAccount.setFundChannel("zy");
				remit = iBaseRemitAccountService.selectRefined(baseRemitAccount);
				if(null != remit && !("").equals(remit))
				{
					remit.setBankId(cachedDictionaryService.getName(remit.getBankId(), DataDicType.BANK));
					maps.put("remit", remit);
					return maps;
				}
			}
		}
		return maps;
	}
	
	//按揭日报表查询列表
	@ApiOperation(value = "按揭日报表查询列表,作者：张虹剑 ",response = Integer.class, httpMethod="POST")
    @ApiImplicitParams({
    	@ApiImplicitParam(name = SystemConsts.MOBILE_FLAG, defaultValue="ios", value = "machineType", required = true, paramType = "header", dataType = "String"),
    	@ApiImplicitParam(name = SystemConsts.HEADER_FOR_TOKEN, defaultValue="token", value = "token", required = true, paramType = "header", dataType = "String")
    })
	@RequestMapping(value="diepuAnJieDayBiaoAppList",method = RequestMethod.POST, produces="application/json;charset=UTF-8")
	public Map<String, Object> diepuAnJieDayBiaoAppList(@RequestBody String requestJsonString)
	{
		Map<String, Object> maps = success();
		maps.put("overdue", false);
		SysUser currentUser = tokenUserHelper.getUser();
		String userId = currentUser.getId();
		
		DiepuAnJieDayBiaoAppList anJieDayBiaoAppExt = new Gson().fromJson(requestJsonString, DiepuAnJieDayBiaoAppList.class);
		String customerName = anJieDayBiaoAppExt.getCustomerName();
		String customerNo = anJieDayBiaoAppExt.getCustomerNo();
		Integer page = anJieDayBiaoAppExt.getPage();
		Integer rows = anJieDayBiaoAppExt.getRows();
		
		String sqlXmls = " select t.code_unit from base_account_busi_unit t where 1 = 1 and t.dp_status = 1 and t.user_id = '"+userId+"' limit 1";
		List<Map<String, String>> mapList = publicService.queryWhereSql(sqlXmls);
		if(null == mapList || 0 == mapList.size())
		{
			return maps;
		}
		
		String whereSql = "";
		whereSql += " SELECT ";
		whereSql += " 	t.id replaceId, ";
		whereSql += " 	t.customer_name customerName, ";
		whereSql += " 	t.customer_no customerNo, ";
		whereSql += " 	t.sign_loan_amount signLoanAmount, ";
		whereSql += " 	t.customer_id customerId, ";
		whereSql += " 	car.name_car_model nameCarModel, ";
		whereSql += " 	car.id carId, ";
		whereSql += " 	saler.unit_code busiCode, ";
		whereSql += " 	t.channel_type channelType, ";
		whereSql += " 	zxquery.credit_result_mark creditResultMark, ";
		whereSql += " 	zxquery.credit_result creditResult ";
		whereSql += " FROM ";
		whereSql += "  yw_business t ";
		whereSql += " LEFT JOIN yw_business_car car ON car.busi_id = t.id ";
		whereSql += " left join base_salersman saler on saler.id = t.salesman_id ";
		whereSql += " left join zx_credit_query zxquery on zxquery.id = t.credit_query_id ";
		whereSql += " where 1 = 1 ";
		whereSql += " and t.dp_status = 1 ";
		whereSql += " and t.busi_status >= 50 and t.busi_status <= 500 and t.added_status1 < 100 ";
		
		if(mapList.size() > 0)
		{
			Map<String, String> m = mapList.get(0);
			String code_unit = m.get("code_unit");
			whereSql += " and saler.salersman_code  = '"+code_unit+"' ";
		}
		
		if(StringUtils.isNotBlank(customerName))
		{
			whereSql += " and t.customer_name like '%"+customerName+"%' ";
			whereSql += " or t.customer_no like '%"+customerName+"%' ";
		}
		
		if(StringUtils.isNotBlank(customerNo))
		{
			whereSql += " and t.customer_name like '%"+customerNo+"%' ";
			whereSql += " or t.customer_no like '%"+customerNo+"%' ";
		}
		
		whereSql += " group by replaceId order by t.created desc ";
		
		//分页条目数
		List<Map<String, String>> result = publicService.queryWhereSql(whereSql);
		int total = 0;
		if(null != result)
		{
			total = result.size();
		}
		
		whereSql += " limit "+((page-1)*rows)+","+(page * rows);
		result = publicService.queryWhereSql(whereSql);
		
		if(null != result && result.size() > 0)
		{
			for(int i=0;i<result.size();i++)
			{
				Map<String, String> aMap = result.get(i);
				String creditResultMark = HtmlUtil.filterHtml(aMap.get("creditResultMark"));
				aMap.put("creditResultMark", creditResultMark);
			}
		}
		Map<String, Object> rowsMaps = CollectionInitUtil.emptyMap();
		rowsMaps.put("records", 1);
		rowsMaps.put("rows", result);
		rowsMaps.put("pageSize", rows);
		rowsMaps.put("page", page);
		rowsMaps.put("total", total);
		maps.put("result", rowsMaps);
        return maps;
	}
	
	//按揭日报表操作
	@ApiOperation(value = "按揭日报表操作，作者：张虹剑 ",response = Integer.class, httpMethod="POST")
    @ApiImplicitParams({
    	@ApiImplicitParam(name = SystemConsts.MOBILE_FLAG, defaultValue="ios", value = "machineType", required = true, paramType = "header", dataType = "String"),
    	@ApiImplicitParam(name = SystemConsts.HEADER_FOR_TOKEN, defaultValue="token", value = "token", required = true, paramType = "header", dataType = "String")
    })
	@RequestMapping(value="diepuAnJieDayBiaoApp",method = RequestMethod.POST, produces="application/json;charset=UTF-8")
	public Map<String, Object> diepuAnJieDayBiaoApp(@RequestBody String requestJsonString)
	{
		Map<String, Object> maps = success();
		maps.put("overdue", false);
		SysUser currentUser = tokenUserHelper.getUser();
		
		DiepuAnJieDayBiaoAppExt diepuAnJieDayBiaoAppExt = new Gson().fromJson(requestJsonString, DiepuAnJieDayBiaoAppExt.class);
		if(null == diepuAnJieDayBiaoAppExt)
		{
			throw new BaseException(ResultFlagType.PARAM_EMPTY.getCode().toString(),ResultFlagType.PARAM_EMPTY.getValue());
		}
		
		String key = diepuAnJieDayBiaoAppExt.getKey();
		String value = diepuAnJieDayBiaoAppExt.getValue();
		String busiId = diepuAnJieDayBiaoAppExt.getBusiId();
		
		YwFees ywFees = new YwFees();
		ywFees.setBusiId(busiId);
		ywFees.setReceiverId(diepuAnJieDayBiaoAppExt.getReceiverId());
		ywFees.setTypeBalance(diepuAnJieDayBiaoAppExt.getTypeBalance());
		ywFees.setAmount(diepuAnJieDayBiaoAppExt.getAmount());
		ywFees.setObjectInsure1(diepuAnJieDayBiaoAppExt.getObjectInsure1());
		ywFees.setObjectInsure2(diepuAnJieDayBiaoAppExt.getObjectInsure2());
		ywFees.setObjectInsure3(diepuAnJieDayBiaoAppExt.getObjectInsure3());
		ywFees.setObjectEarnings1(diepuAnJieDayBiaoAppExt.getObjectEarnings1());
		ywFees.setObjectEarnings2(diepuAnJieDayBiaoAppExt.getObjectEarnings2());
		ywFees.setObjectEarnings3(diepuAnJieDayBiaoAppExt.getObjectEarnings3());
		ywFees.setSignLoanAmount(diepuAnJieDayBiaoAppExt.getSignLoanAmount());
		ywFees.setAccountNameReceiver(diepuAnJieDayBiaoAppExt.getAccountNameReceiver());	
		ywFees.setAccounnNoReceiver(diepuAnJieDayBiaoAppExt.getAccounnNoReceiver());
		ywFees.setNameBankReceiver(diepuAnJieDayBiaoAppExt.getNameBankReceiver());
		ywFees.setRebateDealer(diepuAnJieDayBiaoAppExt.getRebateDealer());
		ywFees.setRebateProvince(diepuAnJieDayBiaoAppExt.getRebateProvince());
		ywFees.setRebateArea(diepuAnJieDayBiaoAppExt.getRebateArea());
		ywFees.setRebateType(diepuAnJieDayBiaoAppExt.getRebateType());
		
		YwBusiness ywBusiness = new YwBusiness();
		ywBusiness.setId(busiId);
		ywBusiness.setAddedStatus1(20);
		YwShouLiService.diepuYwShouLiAnJieDayBiaoBiao(ywFees, ywBusiness, currentUser,key,value);
		return maps;
	}
}
